<template>
  <div class="bedTable">
    <v-table :header="header" :tableList="allpatientinfo"></v-table>
    <!-- <v-pagination :total="total" @currentPage="currentPage"></v-pagination> -->
  </div>
</template>

<script>
// 表格组件
import vTable from "@/components/Table/index";
// 分页组件
// import vPagination from "@/components/pagination/index";

export default {
  data() {
    return {
      header: [
        {
          prop: "bedNum",
          label: "床号",
        },
        {
          prop: "userName",
          label: "姓名",
          render: (h, data) => {
            // render函数元素显示label两种方式 domProps || data.row.userName
            // render函数设置标签props 绑定事件on
            return h(
              "el-button",
              {
                // domProps: {
                //   innerHTML: data.row.userName,
                // },
                props: {
                  type: "text",
                },
                on: {
                  click: () => {
                    this.checkDetails(data.row.userId);
                  },
                },
              },
              data.row.userName
            );
          },
        },
        {
          prop: "sex",
          label: "性别",
        },
        {
          prop: "age",
          label: "年龄",
        },
        {
          prop: "sugarType",
          label: "血糖类型",
        },
        {
          prop: "departmentName",
          label: "科室",
        },
        {
          prop: "doctorName",
          label: "医生",
        },
        {
          prop: "hospitalNum",
          label: "住院号",
        },
        {
          prop: "inHospitalDayNum",
          label: "住院天数",
        },
        {
          prop: "sugarNum",
          label: "最近血糖(mmol/L)",
        },
        {
          prop: "gluceExamtime",
          label: "时间",
        },
        {
          prop: "gluceValue",
          label: "测量段",
        },
        {
          label: "操作",
          render: (h, data) => {
            if (data.row.concernUserId == 1) {
              return (
                <span
                  class="icon_Collection active"
                  onClick={() => {
                    this.follow(data.row);
                  }}
                >
                  <i class="iconfont icon-shoucang1 isactive"></i>
                  取消
                </span>
              );
            } else {
              return (
                <span
                  class="icon_Collection"
                  onClick={() => {
                    this.follow(data.row);
                  }}
                >
                  <i class="iconfont icon-shoucang1"></i>
                  关注
                </span>
              );
            }
          },
        },
      ],
    };
  },
  props: {
    // 所有床位信息
    allpatientinfo: {
      type: Array,
      required: true,
    },
    // 总页数
    // total: {
    //   type: Number,
    //   required: true,
    // },
  },
  components: {
    vTable,
    // vPagination,
  },
  mounted() {},
  methods: {
    // 当前页码
    currentPage(val) {
      this.$emit("highest", val);
    },
    // 取消关注患者,点击关注患者
    follow(row) {
      let data = {
        doctorId: Number(row.doctorId),
        userId: Number(row.userId),
      };
      this.$api
        .attentionUser(data)
        .then((res) => {
          this.$message.success(res.message)
          this.$router.go(0)
        })
        .catch((err) => {});
    },
    // 跳转详情页
    checkDetails(id) {
      this.$router.push({ path: "/patientDetails", query: { id } });
    },
  },
};
</script>

<style lang="scss" scoped>
.bedTable {
  & >>> .active {
    color: #ff0101;
    .isactive {
      &::before {
        color: #ff0101;
      }
    }
  }
}
</style>